﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using MS.InformationManagement.Support;
using MS.InformationManagement.Presenter.Support;
using MS.InformationManagement.Presenter.AnulacionRadicado;
using MS.InformationManagement.Support.Constants;


namespace MS.InformationManagement.WP.Layouts.MS.InformationManagement.WP
{
    public partial class AnulacionRadicado : LayoutsPageBase, IAnulacionRadicadoView
    {
        #region fields

        private AnulacionRadicadoPresenter _presenter;

        #endregion

        #region Properties

        public string Strategy
        {
            get { return Page.Request.QueryString["strategy"]; }
        }
        public string Observaciones { get; set; }
        public bool Result { get; set; }
        public int CurrentId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["ID"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["ID"]);
            }
        }

        #endregion

        #region Form Events

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            btnCancelar.Click += new EventHandler(btnCancelar_Click);
            btnEnviar.Click += new EventHandler(btnEnviar_Click);

            txtObservaciones.Required(ExceptionConstants.ERROR_CAMPO_NULO, "ValBtnEnviar", AjaxControlToolkit.ValidatorCalloutPosition.BottomRight);

  
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Strategy == "rechazar")
                { btnEnviar.Text = "Rechazar"; lblTitle.Text = "Rechazar solicitud de anulación"; }

            if (Strategy == "anular")
                { btnEnviar.Text = "Anular"; lblTitle.Text = "Anular Radicado"; }

            _presenter = new AnulacionRadicadoPresenter(this);
        }

        void btnEnviar_Click(object sender, EventArgs e)
        {
            Observaciones = txtObservaciones.Text;

            if (Strategy == "rechazar")
                _presenter.RechazarSolicitud();

              if (Strategy == "anular")
                  _presenter.AceptarSolicitud();
        }

        void btnCancelar_Click(object sender, EventArgs e)
        {
            this.CloseWindow();
        }

        #endregion

        #region Implemented Methods

        public void Success()
        {
            if (Result == true)
            {
                this._ShowAlertAndClose("Su solicitud ha sido registrada");
            }
            else
            {
                btnCancelar.Enabled = false;
                btnEnviar.Enabled = false;
                this._ShowAlertAndClose("Ha ocurrido un error al ingresar su solicitud");
            }

        }

        #endregion

    }
}
